import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { OrderService } from './order.service';
import { CreateOrderDto, BaseOrderDto, UpdateOrderDto, QueryOrderDto, ListOrderDto } from './dto/order.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('订单表')
@Controller('system/order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}

  @ApiOperation({ summary: '订单表-创建' })
  @ApiDataResponse(BaseOrderDto)
  @RequirePermission('system:order:add')
  @Post()
  create(@Body() body: CreateOrderDto) {
    return this.orderService.create(body);
  }

  @ApiOperation({ summary: '订单表-列表' })
  @ApiDataResponse(ListOrderDto, true, true)
  @RequirePermission('system:order:list')
  @Get('list')
  findAll(@Query() query: QueryOrderDto) {
    return this.orderService.findAll(query);
  }

  @ApiOperation({ summary: '订单表-详情' })
  @ApiDataResponse(BaseOrderDto)
  @RequirePermission('system:order:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.orderService.findOne(id);
  }

  @ApiOperation({ summary: '订单表-修改' })
  @ApiDataResponse()
  @RequirePermission('system:order:edit')
  @Put()
  update(@Body() body: UpdateOrderDto) {
    return this.orderService.update(body);
  }

  // @ApiOperation({ summary: '订单表-删除' })
  // @ApiDataResponse()
  // @RequirePermission('system:order:remove')
  // @Delete(':id')
  // remove(@Param('id') id: string) {
  //   const ids = id.split(',').map((id) => +id);
  //   return this.orderService.remove(ids);
  // }
}
